Add lib types for JSON.rawJSON, JSON.isRawJSON, and reviver context#63248
Add lib types for JSON.rawJSON, JSON.isRawJSON, and reviver context#63248VedantMadane wants to merge 5 commits intomicrosoft:mainfrom
Conversation
Adds esnext.json.d.ts with type definitions for the Stage 4 TC39
proposal-json-parse-with-source (shipped in all major browsers and
Node.js 22+):
- JSON.rawJSON(text): creates a RawJSON object for lossless serialization
- JSON.isRawJSON(value): type guard narrowing to RawJSON
- JSON.parse reviver context: third parameter with { source: string }
Fixes microsoft#61330
The proposal-json-parse-with-source is Stage 4 and part of ES2025, so the lib should live in es2025.json.d.ts, not esnext.json.d.ts.
It isn't, MDN is wrong on this one. It has stage 4 approval, but is not yet in the latest draft: tc39/ecma262#3714 |
|
With 6.0 out as the final release vehicle for this codebase, we're closing all PRs that don't fit the merge criteria for post-6.0 patches. If you think this was a mistake and this PR fits the post-6.0 patch criteria, please post to the 6.0 iteration issue with details (specifically, which PR and which patch criteria it satisfies). Next steps for PRs:
|
|
Reopening as this is still valid (minus commandlineParser.ts) |
RyanCavanaugh noted this PR is still valid minus commandlineParser.ts. Revert commandLineParser.ts to match upstream main.
There was a problem hiding this comment.
Pull request overview
Adds an ES2025-by-feature lib file to type the now-standard JSON.rawJSON, JSON.isRawJSON, and the JSON.parse reviver “source context” capability, and wires it into the es2025 lib plus compiler test coverage.
Changes:
- Introduces
src/lib/es2025.json.d.tsdefiningRawJSONand augmentingJSONwithrawJSON,isRawJSON, and aJSON.parseoverload with acontextparameter. - References the new lib from
src/lib/es2025.d.tsand registerses2025.jsoninsrc/lib/libs.json. - Adds a compiler test (
jsonParseWithSource.ts) and accepted baselines covering all three APIs.
Reviewed changes
Copilot reviewed 5 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
src/lib/es2025.json.d.ts |
Adds RawJSON and JSON API typings for the ES2025 JSON additions. |
src/lib/es2025.d.ts |
Includes the new es2025.json lib in the es2025 umbrella lib. |
src/lib/libs.json |
Registers es2025.json as an available by-feature lib. |
tests/cases/compiler/jsonParseWithSource.ts |
Compiler test exercising rawJSON, isRawJSON, and reviver context. |
tests/baselines/reference/jsonParseWithSource.types |
Baseline for type printing of the new APIs. |
tests/baselines/reference/jsonParseWithSource.symbols |
Baseline for symbol resolution including the new lib. |
tests/baselines/reference/jsonParseWithSource.js |
Baseline for JS emit. |
Adds
es2025.json.d.tswith type definitions for the Stage 4 TC39 proposal-json-parse-with-source which is part of ES2025 and has shipped in all major browsers and Node.js 22+.Summary
JSON.rawJSON(text)- creates a frozenRawJSONobject for lossless JSON serialization (e.g. preserving large-integer precision)JSON.isRawJSON(value)- type-guard that narrows toRawJSONJSON.parserevivercontext- overload whose reviver receives a third parameter{ source: string }containing the original JSON source text of each primitive valueNew files
src/lib/es2025.json.d.tsRawJSONinterface +JSONaugmentationstests/cases/compiler/jsonParseWithSource.tstests/baselines/reference/jsonParseWithSource.*Modified files
src/lib/es2025.d.ts/// <reference lib="es2025.json" />src/lib/libs.jsones2025.jsonsrc/compiler/commandLineParser.tses2025.jsonto its.d.tsFixes #61330